@echo off

set env=%1%
set projectName=%2%
set today=%date:~0,4%%date:~5,2%%date:~8,2%
set slnFolder=C:\GasErpwyy2021
set msbuild="C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild.exe"
set projPath="%slnFolder%\05.UI\%projectName%\website.publishproj"
set publishProfile=%slnFolder%\05.UI\%projectName%\App_Data\PublishProfiles\JenkinsPublishProfile.pubxml

echo "[Debug:info] env=%env%"
echo "[Debug:info] projectName=%projectName%"

::第一次拉取代码Build整个项目并拷贝缺失的dll到站点项目
::If not exist %slnFolder%\05.UI\%projectName%\bin (
	echo "[Debug:info] start restore packages for GasErpwyy2021
	C:\Jenkins\nuget\nuget.exe restore %slnFolder%\GasErpwyy2021.sln
	IF %ERRORLEVEL% NEQ 0 GOTO ERROR
	
	echo "[Debug:info] start build project - AttachPackage
	%msbuild% %slnFolder%\01.Common\AttachPackage\AttachPackage.csproj -t:build /p:WarningLevel=0
	IF %ERRORLEVEL% NEQ 0 GOTO ERROR

	echo "[Debug:info] start build solution GasErpwyy2021
	%msbuild% %slnFolder%\GasErpwyy2021.sln -t:build /p:WarningLevel=0
::)
IF %ERRORLEVEL% NEQ 0 GOTO ERROR

echo "[Debug:info] start publish project %projectName%"
echo "[Debug:info] projPath=%projPath%"
echo "[Debug:info] publishProfile=%publishProfile%"
If "%projectName%" == "trunklpg" (		
	GOTO MSBuildFun
)
If "%projectName%" == "SaaSAPPlpg" (		
	GOTO MSBuildFun
)
If "%projectName%" == "DccAdmin" (	
	GOTO MSBuildFun
)

:MSBuildFun
%msbuild% %projPath% /p:DeployOnBuild=true /p:PublishProfile=%publishProfile% /p:WarningLevel=0
IF %ERRORLEVEL% NEQ 0 GOTO ERROR

:OK
ECHO command success
EXIT 0

:ERROR
ECHO command failed
EXIT 1